package com.yami.shop.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.User;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.dao.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/inv")
@Api(tags = "邀请管理")
public class InvitationController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("queryInv")
    @ApiOperation(value = "邀请管理",notes = "邀请管理")
    public ResponseEntity<IPage<User>> getInvInFo(PageParam page){
            IPage<User> invs = userMapper.selectPage(page,new QueryWrapper<User>()
            .ne("upp_invitatio_code","")
            .isNotNull("upp_invitatio_code")
            .orderByDesc("user_regtime"));
            for(User inv : invs.getRecords()){
                User user = userMapper.selectOne(new QueryWrapper<User>()
                .eq("invitatio_code",inv.getUppInvitatioCode()));
                if(user != null){
                    inv.setUppName(user.getNickName());
                }

            }
            return ResponseEntity.ok(invs);
    }

}
